﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Chinesys.Domain.InputValidations
{
    public abstract class InputValidationBase
    {
        public InputValidationBase()
        {
            this.Errors = new List<InputValidationError>();
        }

        public List<InputValidationError> Errors { get; set; }
        
        public string ErrorSummary
        {
            get
            {
                StringBuilder summary = new StringBuilder();

                if (Errors.Any())
                {
                    foreach (InputValidationError error in Errors)
                    {
                        summary.AppendFormat("Error en el campo {0} - {1}", error.PropertyName, error.ErrorMessage);
                    }
                }

                return summary.ToString();
            }
        }

        public virtual bool IsValid
        {
            get 
            {
                this.Validate();
                return !Errors.Any(); 
            }
        }

        public abstract void Validate();

    }
}
